import type { ProColumns } from '@ant-design/pro-components';
import { Button } from 'antd';
import { ModalType } from './Modals'
import { deleteMedicineAll } from '@/services/medicine'
import showDeleteConfirm from '@/utils/deleteConfirm';
import type { MedicineItem } from '@/interfaces/medicine'
import WithAuthComp from '@/components/WithAuthComp';
import { ROLE } from '@/common/const'

const getColumns: (props) => ProColumns<MedicineItem>[] = (props) => {
    const { modalsRef } = props
    return [
        {
            title: '药品名称',
            dataIndex: 'name',
        },
        {
            title: '库存',
            dataIndex: 'entercount',
            hideInSearch: true
        },
        {
            title: '操作',
            valueType: 'option',
            key: 'option',
            width: 200,
            render: (text, record, _, action) => [
                <Button
                    color="cyan"
                    size='small'
                    type='primary'
                    key="detail"
                    onClick={() => {
                        modalsRef.current.show(ModalType.DETAIL, record.name);
                    }}
                >
                    详情
                </Button>,
                <WithAuthComp authKey={[ROLE.CKY]}>
                    <Button
                        size='small'
                        type='primary'
                        key={"out"}
                        onClick={() => {
                            modalsRef.current.show(ModalType.DELIVERY, record.name);
                        }}
                    >
                        出库
                    </Button>
                </WithAuthComp>
                ,
                <WithAuthComp authKey={[ROLE.RKY]}>
                    <Button
                        size='small'
                        type='primary'
                        key='in'
                        onClick={() => {
                            modalsRef.current.show(ModalType.PUTIN, record.name);
                        }}
                    >
                        入库
                    </Button>
                </WithAuthComp>
                ,
                <Button
                    size='small'
                    type='primary'
                    key='history'
                    onClick={() => {
                        modalsRef.current.show(ModalType.HISTORY, record.name);
                    }}
                >
                    统计
                </Button>,
                <WithAuthComp authKey={[ROLE.ADMIN]}>

                    <Button
                        size='small'
                        type="primary"
                        key='delete'
                        danger
                        onClick={() => {
                            showDeleteConfirm({ id: record.name, action, deleteApi: deleteMedicineAll })
                        }}
                    >
                        删除
                    </Button>
                </WithAuthComp>
                ,
            ],
        },
    ];
}

export default getColumns;